<?php
namespace backend\models;

use common\models\Admin;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;

/**
 * Clue model
 *显示字段

 */
class ContactPeople extends ActiveRecord
{
    const STATUS_DELETED = 0;
    const STATUS_ACTIVE = 10;


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%contact_people}}';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => 'yii\behaviors\TimestampBehavior',
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => [


                    ],
                    ActiveRecord::EVENT_BEFORE_UPDATE => [

                    ]
                ]
            ]
        ];
    }
    /**
     * @inheritdoc
     */
   /* public function rules()
    {
        return [
            ['status', 'default', 'value' => self::STATUS_ACTIVE],
            ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
        ];
    }
   */

    /**
     * @inheritdoc
     */
    public static function findIdentity($id)
    {
        return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
    }

    /**
     * @inheritdoc
     */
    public static function findIdentityByAccessToken($token, $type = null)
    {
        throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
    }

    /**
     * Finds user by username
     *
     * @param string $username
     * @return static|null
     */
    public static function findByUsername($username)
    {
        return static::findOne(['userName' => $username]);
    }
    /**
     * 绑定企业
     */
    public function getEnterprise(){
        return static::hasOne(Enterprises::className(),['id'=>'enterpriseId'])->from(['enterInfo'=>Enterprises::tableName()])->select('enterpriseName');
    }
    /**
     * 绑定企业和城市的关系
     */
    public function getCitys(){
        $enterprise=new Enterprises();
        return $enterprise->hasOne(Region::className(),['code'=>'cityId'])->viaTable('al_enterprises',['id'=>'enterpriseId']);
    }

    /**
     * 绑定省份的关系
     */
    public function getProvinces(){
        $enterprise=new Enterprises();
        return $enterprise->hasOne(Region::className(),['code'=>'provinceId'])->viaTable('al_enterprises',['id'=>'enterpriseId'])->from(['provinces'=>Region::tableName()]);
    }




}
